package com.jiyun.controller;

import com.jiyun.util.OSSUploadUtil;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@CrossOrigin(methods = {RequestMethod.GET, RequestMethod.POST, RequestMethod.OPTIONS})
//@Controller
@RestController
@RequestMapping("upload")
public class UploadController {

//    @RequestMapping("goindex")
//    public String goindex(){
//        return "upload";
//    }
    @RequestMapping("image")
    public String image(MultipartFile file, Model model) throws Exception {
        String sx = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".") + 1);
        String url = OSSUploadUtil.uploadFile(file.getInputStream(), sx);
        System.out.println(url);
        model.addAttribute("img", url);
        return url;
    }

}
